<?php
	echo "<h2 id='contentTitle'>".$pageTitle."</h2>";
	echo $this->renderElement('message');

	echo '<div> Visualize e cadastre as Unidades de sua organização. <br> Cada unidade pode ter funcionários, voluntários e assistidos cadastrados separadamente. <br /><br></div> ';



	if ($othAuth->hasPermission('units/add/')) {
		$addButton = "<span class=\"buttonAdd\">Cadastrar unidade</span>";
		echo html_entity_decode($html->link($addButton, '/units/add/',array('class'=>'button')));
	}

	if (isset($units) && is_array($units) && (!empty($units))) {
		echo "<table>";
				/* Cabeçalho */
		echo "<thead>";
		echo "<div></div>";
		echo "<tr class='tableHeader'>";
		echo "<th class='tableHeaderBegin'>Nome</th>";
		$group = $othAuth->getData('group');
		$level =$group['level'];
		if ($level < 100) {
			echo "<th class='tableHeaderMiddle'>Entidade</th>";
		}

		if ($othAuth->hasPermission('units/edit/')) {
			echo "<th class='tableHeaderMiddle'>Editar</th>";
		}
		if ($othAuth->hasPermission('units/delete/')) {
			echo "<th class='tableHeaderEnd'>Excluir</th>";
		}
		echo "</tr>";
		echo "</thead>";

		/* Rodapé */
		echo "<tfoot>";
		echo "<tr class='tableFooter'>
		<td colspan='100%'></td>
		</tr>";
		echo "</tfoot>";

		$i=0;
		foreach ($units as $unit) {
			if (($i++ % 2) == 1) $zebrado = " class='oddTr' ";
			else $zebrado = "";
			echo "<tr ".$zebrado.">";
			echo "<td>".$html->link($unit['Unit']['nome'],'/units/view/'.$unit['Unit']['id'])."</td>";
			if ($level < 100) {
				echo "<td>".$html->link($unit['Organization']['nome'],'/organizations/view/'.$unit['Organization']['id'])."</td>";
			}
			if ($othAuth->hasPermission('units/edit/')) {
				echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('fileedit.png',array('class'=>'icon')), '/units/edit/'.$unit['Unit']['id']))."</td>";
			}
			if ($othAuth->hasPermission('units/delete/')) {
				echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('filedel.png',array('class'=>'icon')), '/units/delete/'.$unit['Unit']['id'], array(), 'Confirma a exclusão deste item?'))."</td>";
			}
			echo "</tr>";
		}
		echo "</table>";
	}
